# cluster
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt

class ClusterUtils(object):
    def __init__(self):
        self.df = pd.read_csv('./scenic_data.csv')
       


    def get_k(self):
            #提取特征并标准化
            features = self.df[['non_weekend_ratio', 'out_province_ratio', 'elderly_ratio']]
            scaler = StandardScaler()
            scaler_features = scaler.fit_transform(features)

            scores =[]
            for k in range(2,6):
                kmeans = KMeans(n_clusters=k, random_state=42 )
                labels = kmeans.fit_predict(scaler_features)
                scores.append(silhouette_score(scaler_features,labels))
            plt.plot(range(2,6),scores)
            plt.show()
            
if __name__ =='__main__':
    cu = ClusterUtils()
    cu.get_k()
